
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/17 17:25
 */

#include "iostream"
#include "algorithm"

using namespace std;

struct d {
    int y;
    int r;
};

bool cmp(d a, d b) {
    return a.y < b.y;
}

int main() {
    int n;
    cin >> n;
    d data[n];
    int sum = 0;
    int res;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &data[i].y, &data[i].r);
        sum += data[i].r;
        res = min(res, data[i].y);
    }

    sort(data, data + n, cmp);

    int tmp = res;
    int summ = sum;
    for (int i = 0; i < n; ++i) {
        if (tmp != data[i].y) {
            if (summ >= sum) {
                res = data[i].y;
                sum = summ;
            }
            tmp = data[i].y;
        }
        if (!data[i].r) summ++;
        else summ--;
    }

    if (summ > sum) {
        res = data[n - 1].y;
        sum = summ;
    }

    cout << res;

    return 0;
}